package com.demo.demo.object_properties;

import com.demo.demo.TestConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 配置的对象需要有setter
 */
@Component
@ConfigurationProperties("userconf")
public class ObjectPropertyDemo implements TestConfig.Show {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private User user;

    @Override
    public void showAll() {
        logger.info("username={}", user.getUsername());
        logger.info("password={}", user.getPassword());
    }

    public void setUser(User user) {
        this.user = user;
    }

    public static class User {
        private String username = "username";
        private String password = "password";

        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }
    }
}
